package com.seashop.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author moredln
 * @desc 获取当前环境
 * @date 11/24/20 11:39 PM
 */
@Component
@Slf4j
public class PropertiesConfig implements ApplicationContextAware {

    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    // 获取当前环境
    public static String getActiveProfile() {
        String activeProfile = context.getEnvironment().getActiveProfiles()[0];
        log.info("当前环境：{}", activeProfile);
        return activeProfile;
    }

}
